﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.MdNavigation.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.MdNavigation;
/// <summary>
/// 添加网站导航服务
/// </summary>
public class InsertMdNavigationService : ApiBase<RequestInsertMdNavigationModel>
{
    /// <summary>
    /// 网站导航仓储
    /// </summary>
    public MdNavigationRep mdNavigationRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new MdNavigationModel();

        model.Name = Parameter.Name;
        model.PagePath = Parameter.PagePath;
        model.Link = Parameter.Link;
        model.IsExternalLink = Parameter.IsExternalLink;
        model.Sort = Parameter.Sort;
        model.Status = Parameter.Status;
        model.DelFlag = "0";
        model.CreateBy = userKey?.ToString();
        model.CreateTime = DateTime.Now;

        var res = mdNavigationRep.Insert(model);

        if (Convert.ToInt64(res) > 0)
        {
            Result.Data = mdNavigationRep.GetMdNavigationById(Convert.ToInt64(res));
        }
        else
        {
            Result.Data = res;
        }
    }
}

